package run.bottle.app.utils;

import io.netty.channel.Channel;
import run.bottle.app.model.dto.UserDTO;
import run.bottle.app.model.support.BottleConst;

import java.util.ArrayList;
import java.util.UUID;

/**
 * @author: Lycheng
 * @date: 2020/10/28 21:57
 */
public class BottleUtils {

    public static String randomUUIDWithoutDash() {
        return UUID.randomUUID().toString().replace("-","");
    }

    public static void addUser(UserDTO userDTO) {
        BottleConst.USER.put(userDTO.get_id(), userDTO);
    }

    public static void addChannel(Channel channel) {
        BottleConst.CHANNELS.add(channel);
    }

    public static void addUserChannel(String userId,Channel channel) {
        BottleConst.USERS_CHANNER.put(userId, channel);
    }



    public static void addToGroup(String groupId, UserDTO userDTO, Channel channel) {

        if (!BottleConst.GROUP_CHANNER.containsKey(groupId)) {
            BottleConst.GROUP_CHANNER.put(groupId, new ArrayList<>());
        }
        BottleConst.GROUP_CHANNER.get(groupId).add(channel);

        addUser(userDTO);
        addChannel(channel);
        addUserChannel(userDTO.get_id(), channel);
    }
}
